var egret = window.egret;var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
/**
 * 游戏的基类
 */
var baseGame = (function (_super) {
    __extends(baseGame, _super);
    function baseGame() {
        var _this = _super.call(this) || this;
        _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
        return _this;
    }
    /** 游戏被添加到场景上的时候 */
    baseGame.prototype.onAddToStage = function (event) {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        this.stage.addEventListener(egret.Event.RESIZE, this.onStageSize, this);
        this.RES && RES.loadGroup(this.RES);
    };
    /** 场景大小修改的时候 */
    baseGame.prototype.onStageSize = function (e) {
        //console.log("onStageSize", this.stage.stageWidth, this.gWidth(), this.stage.stageWidth / this.gWidth());
        this.box.scaleX = this.gScaleX();
        this.box.scaleY = this.gScaleY();
    };
    /** 游戏的宽度 */
    baseGame.prototype.gScaleX = function () {
        return this.stage.stageWidth / this.width;
    };
    /** 游戏的高度 */
    baseGame.prototype.gScaleY = function () {
        return this.stage.stageHeight / this.height;
    };
    /** 游戏显示 */
    baseGame.prototype.gameShow = function () {
        this.onStageSize(null);
    };
    return baseGame;
}(egret.DisplayObjectContainer));
__reflect(baseGame.prototype, "baseGame");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-2015, Egret Technology Inc.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var LoadingUI = (function (_super) {
    __extends(LoadingUI, _super);
    function LoadingUI() {
        var _this = _super.call(this) || this;
        _this.createView();
        return _this;
    }
    LoadingUI.prototype.createView = function () {
        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.y = 300;
        this.textField.width = 480;
        this.textField.height = 100;
        this.textField.textAlign = "center";
    };
    LoadingUI.prototype.setProgress = function (current, total) {
        //显示进度
        this.textField.text = "Loading..." + current + "/" + total;
    };
    return LoadingUI;
}(egret.Sprite));
__reflect(LoadingUI.prototype, "LoadingUI");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-2015, Egret Technology Inc.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var Main = (function (_super) {
    __extends(Main, _super);
    function Main() {
        var _this = _super.call(this) || this;
        _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
        return _this;
    }
    Main.prototype.onAddToStage = function (event) {
        //设置加载进度界面
        //Config to load process interface
        this.loadingView = new LoadingUI();
        this.stage.addChild(this.loadingView);
        //初始化Resource资源加载库
        //initiate Resource loading library
        RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
        RES.loadConfig("default.res.json", "resource/");
    };
    /**
     * 配置文件加载完成,开始预加载preload资源组。
     * configuration file loading is completed, start to pre-load the preload resource group
     */
    Main.prototype.onConfigComplete = function (event) {
        RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
        RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onResourceLoadComplete, this);
        RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onResourceLoadError, this);
        RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
        RES.loadGroup("preload");
    };
    /**
     * preload资源组加载完成
     * Preload resource group is loaded
     */
    Main.prototype.onResourceLoadComplete = function (event) {
        if (event.groupName == "preload") {
            this.stage.removeChild(this.loadingView);
            // RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onResourceLoadComplete, this);
            // RES.removeEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onResourceLoadError, this);
            // RES.removeEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
            this.bgame = new hong.cyxxgame();
            this.addChild(this.bgame);
            console.log("add game");
            if (egret.RuntimeType.WXGAME == egret.Capabilities.runtimeType)
                wx.showShareMenu({ withShareTicket: false, success: function (res) { }, fail: function (res) { }, complete: function (res) { } });
        }
        else {
            this.bgame.gameShow();
        }
    };
    /**
     * 资源组加载出错
     *  The resource group loading failed
     */
    Main.prototype.onResourceLoadError = function (event) {
        //TODO
        console.warn("Group:" + event.groupName + " has failed to load");
        //忽略加载失败的项目
        //Ignore the loading failed projects
        this.onResourceLoadComplete(event);
    };
    /**
     * preload资源组加载进度
     * Loading process of preload resource group
     */
    Main.prototype.onResourceProgress = function (event) {
        if (event.groupName == "preload") {
            this.loadingView.setProgress(event.itemsLoaded, event.itemsTotal);
        }
        else {
        }
    };
    return Main;
}(egret.DisplayObjectContainer));
__reflect(Main.prototype, "Main");
var DebugPlatform = (function () {
    function DebugPlatform() {
    }
    DebugPlatform.prototype.getUserInfo = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, { nickName: "username" }];
            });
        });
    };
    DebugPlatform.prototype.login = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    return DebugPlatform;
}());
__reflect(DebugPlatform.prototype, "DebugPlatform", ["Platform"]);
if (!window.platform) {
    window.platform = new DebugPlatform();
}
var hong;
(function (hong) {
    /** 成语消消乐的主类 */
    var cyxxgame = (function (_super) {
        __extends(cyxxgame, _super);
        function cyxxgame() {
            var _this = _super.call(this) || this;
            /** 每个元素的宽带 */
            _this.cellWidth = 54;
            /** 每个元素的高带 */
            _this.cellHeight = 54;
            /** x轴需要的图标数量 */
            _this.Xnum = 8;
            /** y轴需要的图标数量 */
            _this.Ynum = 16;
            /** 显示元素列表 */
            _this.list = null;
            /** 过去的秒数 */
            _this.sec = 0;
            /** 游戏类型 0:等级类型 1:年级类型 */
            _this.gTp = 0;
            /** 等级 */
            _this.Lv = 0;
            /** 等级空白高度 */
            _this.topHeight = 0;
            _this.RES = "cyxxl";
            _this.list = [];
            _this.selCY = "";
            _this.tip = new egret.TextField();
            _this.tip.x = 10;
            _this.tip.y = 20;
            _this.tip.size = 18;
            _this.sec = 0;
            egret.setInterval(_this.onTime, _this, 1000);
            _this.addChild(_this.tip);
            _this.btref = new egret.TextField();
            _this.btref.touchEnabled = true;
            _this.btref.border = true;
            _this.btref.text = "刷新";
            _this.btref.size = 18;
            _this.btref.y = 20;
            _this.btref.x = (_this.Xnum - 4) * _this.cellWidth;
            _this.btref.addEventListener(egret.TouchEvent.TOUCH_TAP, _this.gameShow, _this);
            _this.addChild(_this.btref);
            _this.box = new egret.DisplayObjectContainer();
            _this.box.y = 60;
            _this.addChild(_this.box);
            _this.selMask = [];
            for (var i = 0; i < 4; i++) {
                _this.selMask[i] = new egret.Shape();
                _this.selMask[i].graphics.beginFill(0xffffff, 0.3);
                _this.selMask[i].graphics.drawRect(0, 0, 54, 54);
                _this.selMask[i].graphics.endFill();
                _this.selMask[i].visible = false;
            }
            _this.selItem = [];
            //this.touchEnabled = true;
            _this.box.addEventListener(egret.TouchEvent.TOUCH_TAP, _this.onClick, _this);
            return _this;
        }
        /** 每秒刷新时间 */
        cyxxgame.prototype.onTime = function () {
            if (this.sec > 0) {
                this.sec--;
                this.tip.text = "等级: " + (this.Lv + 1) + " 时间: " + this.sec;
                if (this.sec == 0) {
                    var tx = new egret.TextField();
                    tx.text = "你输了";
                    tx.size = 50;
                    tx.y = this.stage.stageHeight / 2;
                    tx.x = (this.box.width - tx.textWidth) / 2;
                    this.box.addChild(tx);
                    this.Lv = 0;
                }
            }
        };
        /** 游戏显示 */
        cyxxgame.prototype.gameShow = function () {
            this.box.removeChildren();
            this.CYlist || (this.CYlist = RES.getRes("cy_json"));
            var cy = this.CYlist.list[Math.random() * this.CYlist.list.length | 0];
            this.sec = this.CYlist.lv[this.Lv][1];
            this.topHeight = (((this.Ynum - this.CYlist.lv[this.Lv][0]) / 2) | 0) * this.cellHeight;
            for (; cy.length < this.Xnum * this.CYlist.lv[this.Lv][0];) {
                cy += this.CYlist.list[Math.random() * this.CYlist.list.length | 0];
            }
            for (var i = 0; i < this.CYlist.lv[this.Lv][0]; i++) {
                this.list[i] = [];
                for (var j = 0; j < this.Xnum; j++) {
                    if (cy.length == 0)
                        cy = this.CYlist.list[Math.random() * this.CYlist.list.length | 0];
                    var cm = new hong.cyxxItem("T");
                    if (Math.random() * 100 < 50) {
                        cm.text = cy.charAt(0);
                        cy = cy.substr(1);
                    }
                    else {
                        cm.text = cy.charAt(cy.length - 1);
                        cy = cy.substr(0, cy.length - 1);
                    }
                    this.list[i][j] = cm;
                    cm.x = j * this.cellWidth;
                    cm.y = i * this.cellHeight + this.topHeight;
                    cm.touchEnabled = true;
                    this.box.addChild(cm);
                }
            }
            for (var i = 0; i < 4; i++) {
                this.box.addChild(this.selMask[i]);
                this.selMask[i].visible = false;
            }
            this.selItem = [];
            this.selCY = "";
            _super.prototype.gameShow.call(this);
        };
        /** 游戏的宽度 */
        cyxxgame.prototype.gScaleX = function () {
            return this.stage.stageWidth / (this.Xnum * this.cellWidth);
        };
        /** 游戏的高度 */
        cyxxgame.prototype.gScaleY = function () {
            return (this.stage.stageHeight - 60) / (this.Ynum * this.cellHeight);
        };
        /** 点击了元素 */
        cyxxgame.prototype.onClick = function (e) {
            var cItem = e.target;
            var scy = this.selCY + cItem.text;
            for (var i = 0; i < this.CYlist.list.length; i++) {
                if (this.CYlist.list[i].indexOf(scy) == 0) {
                    if (scy.length == this.CYlist.list[i].length) {
                        for (var j = 0; j < this.selItem.length; j++) {
                            this.list[(this.selItem[j].y - this.topHeight) / this.cellHeight][this.selItem[j].x / this.cellWidth] = null;
                            this.box.removeChild(this.selItem[j]);
                        }
                        this.list[(cItem.y - this.topHeight) / this.cellHeight][cItem.x / this.cellWidth] = null;
                        this.box.removeChild(cItem);
                        this.reShow();
                        this.selCY = "";
                        this.selItem = [];
                    }
                    else {
                        this.selItem.push(cItem);
                        this.selCY += cItem.text;
                        this.selMask[this.selItem.length - 1].visible = true;
                        this.selMask[this.selItem.length - 1].x = cItem.x;
                        this.selMask[this.selItem.length - 1].y = cItem.y;
                    }
                    return;
                }
            }
            for (var i = 1; i < this.selMask.length; i++) {
                this.selMask[i].visible = false;
            }
            this.selItem = [cItem];
            this.selCY = cItem.text;
            this.selMask[this.selItem.length - 1].visible = true;
            this.selMask[this.selItem.length - 1].x = cItem.x;
            this.selMask[this.selItem.length - 1].y = cItem.y;
        };
        /** 刷新显示的元素 */
        cyxxgame.prototype.reShow = function () {
            // for(let i=0;i<this.Xnum;i++){
            // 	let cj = this.Ynum-1;
            // 	for(;cj>-1;cj--){ //取最后一个非空元素
            // 		if(this.list[cj][i] == null) break;
            // 	}
            // 	if(cj > -1) console.log("move", i, cj);
            // 	for(let j=cj-1;j>-1;j--){
            // 		if(this.list[j][i]){
            // 			this.list[cj][i] = this.list[j][i];
            // 			this.list[j][i] = null;
            // 			egret.Tween.get(this.list[cj][i]).to({y:cj*this.cellHeight}, 500);
            // 			cj--;
            // 		}
            // 	}
            // }
            if (this.box.numChildren == 4) {
                var tx = new egret.TextField();
                tx.text = "你真棒赢了";
                tx.size = 50;
                tx.y = this.stage.stageHeight / 2;
                tx.x = (this.box.width - tx.textWidth) / 2;
                this.box.addChild(tx);
                egret.setTimeout(function () {
                    this.Lv += 1;
                    this.gameShow();
                }, this, 5000);
            }
            console.log("box.numChildren", this.box.numChildren);
            for (var i = 0; i < this.selMask.length; i++) {
                this.selMask[i].visible = false;
            }
        };
        return cyxxgame;
    }(baseGame));
    hong.cyxxgame = cyxxgame;
    __reflect(cyxxgame.prototype, "hong.cyxxgame");
})(hong || (hong = {}));
var hong;
(function (hong) {
    /** 显示元素 */
    var cyxxItem = (function (_super) {
        __extends(cyxxItem, _super);
        function cyxxItem(tv, h, w) {
            if (h === void 0) { h = 54; }
            if (w === void 0) { w = 54; }
            var _this = _super.call(this) || this;
            _this.tx = new egret.TextField();
            _this.tx.text = tv;
            _this.bg = new egret.Bitmap();
            _this.bg.texture = RES.getRes("ic_png");
            _this.addChild(_this.bg);
            _this.tx.x = 34;
            _this.tx.y = 36;
            _this.tx.size = 120;
            _this.tx.textColor = 0x90df90;
            _this.tx.bold = true;
            _this.addChild(_this.tx);
            _this.scaleX = w / 188;
            _this.scaleY = h / 188;
            return _this;
        }
        Object.defineProperty(cyxxItem.prototype, "text", {
            /** 获取文字 */
            get: function () {
                return this.tx.text;
            },
            /** 设置文字 */
            set: function (t) {
                this.tx.text = t;
            },
            enumerable: true,
            configurable: true
        });
        return cyxxItem;
    }(egret.DisplayObjectContainer));
    hong.cyxxItem = cyxxItem;
    __reflect(cyxxItem.prototype, "hong.cyxxItem");
})(hong || (hong = {}));
var hong;
(function (hong) {
    /** 成语消消乐的主类 */
    var xxlgame = (function (_super) {
        __extends(xxlgame, _super);
        function xxlgame() {
            var _this = _super.call(this) || this;
            /** 每个元素的宽带 */
            _this.cellWidth = 54;
            /** 每个元素的高带 */
            _this.cellHeight = 54;
            /** x轴需要的图标数量 */
            _this.Xnum = 8;
            /** y轴需要的图标数量 */
            _this.Ynum = 16;
            /** 显示元素列表 */
            _this.list = null;
            _this.RES = "xxl";
            _this.list = [];
            _this.selMask = new egret.Shape();
            _this.selMask.graphics.beginFill(0xffffff, 0.3);
            _this.selMask.graphics.drawRect(0, 0, 54, 54);
            _this.selMask.graphics.endFill();
            _this.selMask.visible = false;
            _this.selItem = null;
            //this.touchEnabled = true;
            _this.addEventListener(egret.TouchEvent.TOUCH_TAP, _this.onClick, _this);
            return _this;
        }
        /** 游戏显示 */
        xxlgame.prototype.gameShow = function () {
            this.removeChildren();
            for (var i = 0; i < this.Ynum; i++) {
                this.list[i] = [];
                for (var j = 0; j < this.Xnum; j++) {
                    var cm = new cellM();
                    cm.texture = RES.getRes(((Math.random() * 5 + 1) | 0).toString());
                    this.list[i][j] = cm;
                    cm.x = j * this.cellWidth;
                    cm.y = i * this.cellHeight;
                    cm.touchEnabled = true;
                    this.addChild(cm);
                }
            }
            this.addChild(this.selMask);
            _super.prototype.gameShow.call(this);
        };
        /** 游戏的宽度 */
        xxlgame.prototype.gWidth = function () {
            return this.Xnum * this.cellWidth;
        };
        /** 游戏的高度 */
        xxlgame.prototype.gHeight = function () {
            return this.Ynum * this.cellHeight;
        };
        /** 点击了元素 */
        xxlgame.prototype.onClick = function (e) {
            var _this = this;
            var _loop_1 = function () {
                if (!this_1.selItem)
                    return "break"; //没有选择元素需要交换检查
                var cItem = e.target;
                if (this_1.selItem.texture == cItem.texture)
                    return { value: void 0 }; //相同的元素不交换
                if (Math.abs(cItem.x - this_1.selItem.x) / this_1.cellWidth + Math.abs(cItem.y - this_1.selItem.y) / this_1.cellHeight > 1)
                    return "break";
                var sx1 = this_1.selItem.x / this_1.cellWidth, sy1 = this_1.selItem.y / this_1.cellHeight, sx2 = cItem.x / this_1.cellWidth, sy2 = cItem.y / this_1.cellHeight;
                var dlist = [], dmap = {}, inl = 0;
                dmap[sx2 + "_" + sy2] = 1;
                this_1.checkItem(dlist, dmap, this_1.selItem, cItem);
                while (inl < dlist.length) {
                    this_1.checkItem(dlist, dmap, dlist[inl], cItem);
                    inl++;
                }
                if (dlist.length < 2) {
                    dmap = {};
                    dlist = [];
                    inl = 0;
                }
                else {
                    dlist.push(cItem);
                    inl++;
                }
                dmap[sx1 + "_" + sy1] = 1;
                var cl = inl;
                this_1.checkItem(dlist, dmap, cItem, this_1.selItem);
                while (inl < dlist.length) {
                    this_1.checkItem(dlist, dmap, dlist[inl], this_1.selItem);
                    inl++;
                }
                if (dlist.length - cl > 1) {
                    dlist.push(this_1.selItem);
                }
                else {
                    dlist = dlist.slice(0, cl);
                }
                if (dlist.length > 1) {
                    this_1.list[sy2][sx2] = this_1.selItem;
                    this_1.list[sy1][sx1] = cItem;
                    egret.Tween.get(this_1.selItem).to({ x: cItem.x, y: cItem.y }, 400);
                    egret.Tween.get(cItem).to({ x: this_1.selItem.x, y: this_1.selItem.y }, 500).call(function () {
                        //if(this.selItem.texture == dlist[0].texture){
                        //dlist.push(this.selItem);
                        //this.removeChild(this.selItem);
                        //this.list[cItem.y/this.cellHeight][cItem.x/this.cellWidth] = null;
                        //console.log("del", cItem.x/this.cellWidth, cItem.y/this.cellHeight);
                        //}else{
                        //dlist.push(cItem);
                        //this.removeChild(cItem);
                        //this.list[this.selItem.y/this.cellHeight][this.selItem.x/this.cellWidth] = null;
                        //console.log("del", this.selItem.x/this.cellWidth, this.selItem.y/this.cellHeight);
                        //}
                        for (var i = 0; i < dlist.length; i++) {
                            console.log("delx", dlist[i].x / _this.cellWidth, dlist[i].y / _this.cellHeight);
                            _this.removeChild(dlist[i]);
                            _this.list[dlist[i].y / _this.cellHeight][dlist[i].x / _this.cellWidth] = null;
                        }
                        _this.selItem = null;
                        _this.selMask.visible = false;
                        _this.reShow();
                    }, this_1);
                    return { value: void 0 };
                }
            };
            var this_1 = this;
            //console.log(e.target);
            do {
                var state_1 = _loop_1();
                if (typeof state_1 === "object")
                    return state_1.value;
                if (state_1 === "break")
                    break;
            } while (false);
            this.selItem = e.target;
            this.selMask.visible = true;
            this.selMask.x = this.selItem.x;
            this.selMask.y = this.selItem.y;
        };
        /** 检查4方向的元素是否相同 */
        xxlgame.prototype.checkItem = function (dl, dm, wi, ci) {
            var cx = wi.x / this.cellWidth, cy = wi.y / this.cellHeight;
            var cv = [[0, 1], [0, -1], [1, 0], [-1, 0]];
            for (var i = 0; i < cv.length; i++) {
                var nx = cx + cv[i][0], ny = cy + cv[i][1];
                if (nx < 0 || ny < 0 || nx >= this.Xnum || ny >= this.Ynum)
                    continue;
                if (this.list[ny][nx] == null || this.list[ny][nx].texture != ci.texture)
                    continue;
                if ((nx + "_" + ny) in dm)
                    continue;
                dl.push(this.list[ny][nx]);
                dm[nx + "_" + ny] = 1;
            }
        };
        /** 刷新显示的元素 */
        xxlgame.prototype.reShow = function () {
            for (var i = 0; i < this.Xnum; i++) {
                var cj = this.Ynum - 1;
                for (; cj > -1; cj--) {
                    if (this.list[cj][i] == null)
                        break;
                }
                if (cj > -1)
                    console.log("move", i, cj);
                for (var j = cj - 1; j > -1; j--) {
                    if (this.list[j][i]) {
                        this.list[cj][i] = this.list[j][i];
                        this.list[j][i] = null;
                        egret.Tween.get(this.list[cj][i]).to({ y: cj * this.cellHeight }, 500);
                        cj--;
                    }
                }
            }
        };
        return xxlgame;
    }(baseGame));
    hong.xxlgame = xxlgame;
    __reflect(xxlgame.prototype, "hong.xxlgame");
    /** 每个元素的类 */
    var cellT = (function (_super) {
        __extends(cellT, _super);
        function cellT() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        return cellT;
    }(egret.TextField));
    __reflect(cellT.prototype, "cellT");
    /** 每个元素的类 */
    var cellM = (function (_super) {
        __extends(cellM, _super);
        function cellM() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        return cellM;
    }(egret.Bitmap));
    __reflect(cellM.prototype, "cellM");
})(hong || (hong = {}));

;window.Main = Main;